package edu.pw.p2pclient.networking.webservice;

import java.lang.reflect.Type;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

public class Response {
	protected int mExitCode = 0;
	protected String mMessage = "";

	public Response(int exitCode, String message) {
		mExitCode = exitCode;
		mMessage = message;
	}

	public int getExitCode() {
		return mExitCode;
	}

	public String getMessage() {
		return mMessage;
	}

	public boolean isSuccessfull() {
		return mExitCode > 0;
	}

	public final static JsonDeserializer<Response> deserializer = new JsonDeserializer<Response>() {

		@Override
		public Response deserialize(JsonElement json, Type typeOfT,
				JsonDeserializationContext context) throws JsonParseException {

			int exitCode = json.getAsJsonObject().get("exitCode").getAsInt();
			String message = json.getAsJsonObject().get("message")
					.getAsString();

			return new Response(exitCode, message);
		}
	};
}